<template>
  <div id="app">
    <Header :bgcolor="'rgba(0,0,0,0.8)'" />
    <router-view />
    <ConfirmOrder ref="ConfirmOrder" />
    <PayTip ref="PayTip" />
  </div>
</template>

<script>
import { getPlatform } from '@/plugins/string'

export default {
  name: 'App',
  components: {
    ConfirmOrder: _ => import('@/components/common/ConfirmOrder'),
    PayTip: _ => import('@/components/common/PayTip'),
    Header: _ => import('@/components/common/Header'),
  },
  mounted() {
    // 弹框
    this.$vgo.on('showDialogModal', obj => {
      this.showModal(obj)
    })
  },
  methods: {
    showModal(obj) {
      // console.log(obj)
      if(!obj.builtIn) {
        obj.builtIn = false
      }
      if(!obj.isManage) {
        obj.isManage = false
      }
      if(!obj.data) {
        obj.data = ''
      }
      this.$refs[obj.name].openDialog({builtIn: obj.builtIn, isManage: obj.isManage, data: obj.data, imgFlag: obj.imgFlag})
    }
  },
  created() {
    // 获取官网配置信息
    this.$store.dispatch('getSiteconfigsInfo')

    if (!getPlatform()) {
      let originUrl = location.origin + '/'
      // 如果是手机，跳转手机网站
      let url = originUrl + 'm/'
      if (location.hash.indexOf('home') !== -1) {
        
      } else if (location.hash.indexOf('product') !== -1) {
        url = originUrl + 'm/product.html'
        let str = location.hash.split('?')[1]
        if (str) {
          url = `${originUrl}m/product.html?${str}`
        }
      } else if (location.hash.indexOf('panomarket-detail') !== -1) {
        let id = location.hash.split('/')[2] || 1
        url = `${originUrl}m/panomarketDetail.html?id=${id}`
      } else if (location.hash.indexOf('author-detail') !== -1) {
        let id = location.hash.split('/')[2] || 1
        url = `${originUrl}m/authorDetail.html?id=${id}`
      } else if (location.hash.indexOf('news-detail') !== -1) {
        let id = location.hash.split('/')[2] || 1
        url = `${originUrl}m/newsDetail.html?id=${id}`
      } else if (location.hash.indexOf('panomarket') !== -1) {
        url = originUrl + 'm/panomarket.html'
      } else if (location.hash.indexOf('author') !== -1) {
        url = originUrl + 'm/author.html'
      } else if (location.hash.indexOf('news') !== -1) {
        url = originUrl + 'm/news.html'
      } else if (location.hash.indexOf('about') !== -1) {
        url = originUrl + 'm/about.html'
      } else if (location.hash.indexOf('panomap') !== -1) {
        url = originUrl + 'm/panomap.html'
      }
      // console.log(url)
      window.open(url, '_self')
    }
    // 保存token
    if (location.href.indexOf('access_token') !== -1) {
      this.$auth.getToken()
    }
    // 有token拉取获取用户信息和购物车数据
    if (this.$auth.hasToken()) {
      this.$store.dispatch('getUserInfo')
      this.$store.dispatch('getCartList')
    }
  },
}
</script>

<style lang='stylus'>
@import '~@/assets/style/global.styl'
</style>
